<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Lib\Response;
use App\Http\Model\Hint;
use App\Http\Services\BankBlsServices;

class BankBlsController extends BaseController
{
    private $bankBls_service;

    public function __construct()
    {
        $this->bankBls_service = new BankBlsServices();
    }

    /**
     * @desc 查询用户提现基础信息
     * */
    public function getBankUserBase(Request $request)
    {
        $userId = $this->getLoginUserId();
        if(empty($userId)) {
            Response::returnResult(Hint::LOGIN_OUT);
        }

        $rest = $this->bankBls_service->getBankUserBase($userId);
        if($rest['code'] != Hint::SUCCESS) {
            Response::returnResult($rest['code'], [], $rest['msg']);
        }

        Response::returnResult(Hint::SUCCESS, $rest['data']);
    }

    /**
     * @desc 绑定银行卡
     * */
    public function bindBank(Request $request)
    {
        $province = $request->get('province');
        $openBank = $request->get('openBank');
        $bankNo = $request->get('bankNo');
        $phone = $request->get('phone');
        $bankNo = str_replace(" ", "", $bankNo);
        if(empty($province) || empty($openBank) || empty($bankNo) || empty($phone)) {
            Response::returnResult(Hint::PARAM_ERROR);
        }

        $userId = $this->getLoginUserId();
        if(empty($userId)) {
            Response::returnResult(Hint::LOGIN_OUT);
        }

        $rest = $this->bankBls_service->bindBank($userId, $province, $openBank, $bankNo, $phone);
        if($rest['code'] != Hint::SUCCESS) {
            Response::returnResult($rest['code'], [], $rest['msg']);
        }

        Response::returnResult(Hint::SUCCESS);
    }

    /**
     * @desc 银行卡列表
     * */
    public function bankList(Request $request)
    {
        $userId = $this->getLoginUserId();
        if(empty($userId)) {
            Response::returnResult(Hint::LOGIN_OUT);
        }

        $rest = $this->bankBls_service->bankList($userId);
        if($rest['code'] != Hint::SUCCESS) {
            Response::returnResult($rest['code'], [], $rest['msg']);
        }

        Response::returnResult(Hint::SUCCESS, $rest['data']);
    }

    /**
     * @desc 银行卡删除
     * */
    public function bankDelete(Request $request)
    {
        $userId = $this->getLoginUserId();
        if(empty($userId)) {
            Response::returnResult(Hint::LOGIN_OUT);
        }
        $bankId = $request->get('bankId');
        if(empty($bankId)) {
            Response::returnResult(Hint::PARAM_ERROR);
        }

        $rest = $this->bankBls_service->bankDelete($userId, $bankId);
        if($rest['code'] != Hint::SUCCESS) {
            Response::returnResult($rest['code'], [], $rest['msg']);
        }

        Response::returnResult(Hint::SUCCESS);
    }

    
    
}
